<template>
    <div>
        后台首页
        {{ $store.state.user.username }}

    </div>

    <el-button @click="handleLogout ">退出登录</el-button>
</template>
<script setup>
import  { logout } from '@/api/manager'
import { showModal } from '@/composables/util';
import { useRouter } from 'vue-router';
import { useStore } from 'vuex';
import { toast } from "@/composables/util"
const router = useRouter()
const store = useStore()

function handleLogout (){
    showModal('是否要退出登录？').then(res=>{
        console.log('退出登录');
        // logout().then(res=>{ console.log('退出成功');      })
        logout().finally(()=>{
            store.dispatch("logout")
            // 跳转到首页
            router.push("/login")
            // 提示退出登录成功
            toast("退出登录成功")
        })
        
    })



}
</script>